package com.hangxintong.common.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.hangxintong.common.base.entity.LmAssociation;
import com.hangxintong.common.base.entity.LmUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

@Service
public class TokenService {
    public String getToken(LmUser user) {
        String token = "";

        token = JWT.create().withAudience(user.getMobile())
//                .withClaim("deviceNum", user.getDeviceNum())
                //.withClaim("deviceNum", Result.uuid())
                .sign(Algorithm.HMAC256(user.getPasswd()));
//        withClaim("deviceNum",user.getDeviceNum())
        return token;
    }
    public String geth5Token(Long xid) {
//        String token = JWT.create()
////////                .withClaim("xid", xid)
////////                .sign(Algorithm.HMAC256(xid.toString()));
      String  token = JWT.create()
              .withAudience(xid.toString())
              .sign(Algorithm.HMAC256(xid.toString()));

        return token;
    }
    /**
     * 生成密码
     *
     * @param
     * @return
     */
    public String getPasswd(String passwd) {
        String token = "";
        token = JWT.create().sign(Algorithm.HMAC256(passwd));
        return token;
    }
}